package com.sixth.controller;

import com.sixth.service.UserService;
import com.sixth.until.CommonResult;
import com.sixth.until.WebUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: self-tui-education
 * @description:
 * @author: 厉泽禄
 * @create: 2022-04-21 18:01
 **/
@RestController
@RequestMapping("system/user")
public class UserConterller {
    @Autowired
    private UserService userService;
    @Autowired
    private StringRedisTemplate redisTemplate;

    @GetMapping("updateUserPassword/{oldPassword}/{newPassword}")
    public CommonResult updateUserPassword(@PathVariable String oldPassword, @PathVariable String newPassword){
        return userService.updateUserPassword(oldPassword,newPassword);
    }
    @GetMapping("logout")
    public CommonResult logout(){
        HttpServletRequest request = WebUtil.getRequest();
        String token = request.getHeader("token");
        redisTemplate.delete(token);
        return new CommonResult(2000,"退出成功",null);
    }
}
